From fdc6e1b7831b342a1bdb3bc3be916dbd562e3a5e Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 19 Jan 2005 03:54:43 +0000 Subject: [PATCH] * (bug 730) configurable $wgRCMaxAge; don't try to update purged RC entries --- includes/Article.php | 4 +++- includes/DefaultSettings.php | 4 ++++ includes/RecentChange.php | 26 ++++++++++++++++---------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 56055cc2c5..93a10166e4 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1815,8 +1815,10 @@ class Article { wfSeedRandom(); if ( 0 == mt_rand( 0, 999 ) ) { + # Periodically flush old entries from the recentchanges table. + global $wgRCMaxAge; $dbw =& wfGetDB( DB_MASTER ); - $cutoff = $dbw->timestamp( time() - ( 7 * 86400 ) ); + $cutoff = $dbw->timestamp( time() - $wgRCMaxAge ); $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'"; $dbw->query( $sql ); } diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 785d56260d..f3b5b883b4 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -721,6 +721,10 @@ $wgRCSeconds = false; # Log IP addresses in the recentchanges table $wgPutIPinRC = false; +# Recentchanges items are periodically purged; +# entries older than this many seconds will go. +$wgRCMaxAge = 7 * 24 * 3600; # our one week cutoff + # RDF metadata toggles $wgEnableDublinCoreRdf = false; $wgEnableCreativeCommonsRdf = false; diff --git a/includes/RecentChange.php b/includes/RecentChange.php index 2f15679c38..48fd45fc9e 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -131,16 +131,22 @@ class RecentChange $now = $this->mAttribs['rc_timestamp']; $curId = $this->mAttribs['rc_cur_id']; - # Update rc_this_oldid for the entries which were current - $dbw->update( 'recentchanges', - array( /* SET */ - 'rc_this_oldid' => $oldid - ), array( /* WHERE */ - 'rc_namespace' => $ns, - 'rc_title' => $title, - 'rc_timestamp' => $dbw->timestamp($lastTime) - ), $fname - ); + # Don't bother looking for entries that have probably + # been purged, it just locks up the indexes needlessly. + global $wgRCMaxAge; + $age = time() - wfTimestamp( TS_UNIX, $lastTime ); + if( $age < $wgRCMaxAge ) { + # Update rc_this_oldid for the entries which were current + $dbw->update( 'recentchanges', + array( /* SET */ + 'rc_this_oldid' => $oldid + ), array( /* WHERE */ + 'rc_namespace' => $ns, + 'rc_title' => $title, + 'rc_timestamp' => $dbw->timestamp( $lastTime ) + ), $fname + ); + } # Update rc_cur_time $dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ), -- 2.20.1